using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace FluentTags
{

    public class TableTag : Tag<TableTag>
    {
        public TableTag() : base("table"){}
        
        
        public TableTag(Control control) : this()
        {
            Controls.Add(control);
        }
        
        
        public TableTag Border(string value)
        {   
            Attributes.Add("border", value.ToString());
            return this;
        }
        
        public TableTag Cellpadding(string value)
        {   
            Attributes.Add("cellpadding", value.ToString());
            return this;
        }
        
        public TableTag Cellspacing(string value)
        {   
            Attributes.Add("cellspacing", value.ToString());
            return this;
        }
        
        public TableTag Frame(string value)
        {   
            Attributes.Add("frame", value.ToString());
            return this;
        }
        
        public TableTag Rules(string value)
        {   
            Attributes.Add("rules", value.ToString());
            return this;
        }
        
        public TableTag Summary(string value)
        {   
            Attributes.Add("summary", value.ToString());
            return this;
        }
        
        public TableTag Width(string value)
        {   
            Attributes.Add("width", value.ToString());
            return this;
        }
        
        
        public string BorderAttribute
        {
            get
            {
                return Attributes["border"];
            }
        }
        
        public string CellpaddingAttribute
        {
            get
            {
                return Attributes["cellpadding"];
            }
        }
        
        public string CellspacingAttribute
        {
            get
            {
                return Attributes["cellspacing"];
            }
        }
        
        public string FrameAttribute
        {
            get
            {
                return Attributes["frame"];
            }
        }
        
        public string RulesAttribute
        {
            get
            {
                return Attributes["rules"];
            }
        }
        
        public string SummaryAttribute
        {
            get
            {
                return Attributes["summary"];
            }
        }
        
        public string WidthAttribute
        {
            get
            {
                return Attributes["width"];
            }
        }
        
        
        public TRTag<TableTag> TR()
        {
            var ctrl = new TRTag<TableTag>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public TableTag TR(TRTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public TRTag<TableTag> TR(string text)
        {
            var ctrl = new TRTag<TableTag>(this);
            Controls.Add(ctrl);
            LiteralControl lc = new LiteralControl(text);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public TRTag<TableTag> TR(Control control)
        {
            var ctrl = new TRTag<TableTag>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public TRTag<TableTag> TR(object value)
        {
            return TR(SafeString(value));
        }
        
        
    }

    public class TableTag<ParentType> : ChildTag<TableTag<ParentType>, ParentType>
        where ParentType : HtmlGenericControl
    {
        public TableTag(ParentType parent) : base("table", parent) { }

        
        public TableTag<ParentType> Border(string value)
        {   
            Attributes.Add("border", value.ToString());
            return this;
        }
        
        public TableTag<ParentType> Cellpadding(string value)
        {   
            Attributes.Add("cellpadding", value.ToString());
            return this;
        }
        
        public TableTag<ParentType> Cellspacing(string value)
        {   
            Attributes.Add("cellspacing", value.ToString());
            return this;
        }
        
        public TableTag<ParentType> Frame(string value)
        {   
            Attributes.Add("frame", value.ToString());
            return this;
        }
        
        public TableTag<ParentType> Rules(string value)
        {   
            Attributes.Add("rules", value.ToString());
            return this;
        }
        
        public TableTag<ParentType> Summary(string value)
        {   
            Attributes.Add("summary", value.ToString());
            return this;
        }
        
        public TableTag<ParentType> Width(string value)
        {   
            Attributes.Add("width", value.ToString());
            return this;
        }
        
        
        public string BorderAttribute
        {
            get
            {
                return Attributes["border"];
            }
        }
        
        public string CellpaddingAttribute
        {
            get
            {
                return Attributes["cellpadding"];
            }
        }
        
        public string CellspacingAttribute
        {
            get
            {
                return Attributes["cellspacing"];
            }
        }
        
        public string FrameAttribute
        {
            get
            {
                return Attributes["frame"];
            }
        }
        
        public string RulesAttribute
        {
            get
            {
                return Attributes["rules"];
            }
        }
        
        public string SummaryAttribute
        {
            get
            {
                return Attributes["summary"];
            }
        }
        
        public string WidthAttribute
        {
            get
            {
                return Attributes["width"];
            }
        }
        
        
        public TRTag<TableTag<ParentType>> TR()
        {
            var ctrl = new TRTag<TableTag<ParentType>>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public TableTag<ParentType> TR(TRTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public TRTag<TableTag<ParentType>> TR(string text)
        {
            var ctrl = new TRTag<TableTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(text);
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public TRTag<TableTag<ParentType>> TR(Control control)
        {
            var ctrl = new TRTag<TableTag<ParentType>>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public TRTag<TableTag<ParentType>> TR(object value)
        {
            var ctrl = new TRTag<TableTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(SafeString(value));
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            return ctrl;
        }
        
        
        
    }
}